﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TextUseCase.cs" company="">
//   
// </copyright>
// <summary>
//   The text use case.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.UseCases
{
    using System;

    /// <summary>
    ///   The text use case.
    /// </summary>
    public abstract class TextUseCase : UseCase, ITextUseCase
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TextUseCase"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <param name="service">
        /// The service. 
        /// </param>
        public TextUseCase(ICompoundUseCase parent, IUseCaseInstanceService service)
            : base(parent, service)
        {
        }

        #endregion

        #region Public Events

        /// <summary>
        ///   The text changed.
        /// </summary>
        public event Action<ITextUseCase> TextChanged;

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets the text.
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        public virtual string Text
        {
            get
            {
                return GetValue();
            }

            set
            {
                // TODO Refactor
                throw new NotImplementedException();
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///   The raise text changed.
        /// </summary>
        public void RaiseTextChanged()
        {
            OnTextChanged();
        }

        #endregion

        #region Methods

        /// <summary>
        ///   The get value.
        /// </summary>
        /// <returns> The <see cref="string" /> . </returns>
        protected abstract string GetValue();

        /// <summary>
        ///   The on text changed.
        /// </summary>
        protected virtual void OnTextChanged()
        {
            if (TextChanged != null)
            {
                TextChanged(this);
            }
        }

        #endregion

        // TODO Check default drag/drop behaviour
    }
}